<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="verification-box flexWrap" @tap="goIndex()">
					<image src="../static/public/platform-icon.png" class="platform-icon"></image>
					<image src="../static/user/more-icon.png" class="more-icon"></image>
				</view>
				<view class="coupon-box">
					<view class="coupon-item flexWrapNo" v-for="(item,index) in couponList" :key='index'>
						<view class="coupon-left flexWarpCenterColumn">
							<view class="coupon-money">{{parseInt(item.price)}}</view>
							<view>可用余额</view>
						</view>
						<view class="coupon-right flexWarpCenterColumn">
							<view class="coupon-title">{{item.title}}</view>
							<view>面值: ¥{{item.price}}</view>
							<view>有效期:{{item.start_time}}至{{item.end_time}}</view>
							<!-- <view>适用店铺:{{item.shop_name}}</view> -->
							<image src="../static/home/coupon-icon.png" class="coupon-icon"></image>
						</view>
						<view class="user-btn" @tap="goUse(item.store_id)">
							去使用
							<image src="../static/home/righttop.png" class="righttop-icon"></image>
						</view>
					</view>
					<view class="empty-box flexWarpCenterColumn" v-if="couponList.length==0">
						<image src="/static/empty-img.png" class="empty-image"></image>
						<view class="empty-tips">暂无优惠券</view>
					</view>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc:0,
				couponList:[]
			}
		},
		onReady(){
			setTimeout(() => {
				this.pageOpc=1
			}, 100)
		},
		onShow() {
			this.getCouponlist();
		},
		methods: {
			// 获取优惠券列表
			getCouponlist(){
				this.$request.post(this.$api.couponList, {
					
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						for (let i in data) {
							data[i].start_time=this.$tools.formatDay(data[i].start_time)
							data[i].end_time=this.$tools.formatDay(data[i].end_time)
						}
						this.couponList=data
						console.log(this.couponList)
					}
				})
			},
			goIndex(){
				uni.switchTab({
					url:'/pages/home'
				})
			},
			goUse(store_id){
				uni.navigateTo({
					url:'/moduleA/home?store_id='+store_id
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 28upx;
	}
	.verification-box{
		height: 144rpx;
		background: #232428;
		border-radius: 20rpx;
		padding: 0 36upx;
		.platform-icon{
			width: 174upx;
			height: 72upx;
			flex: none;
		}
		.more-icon{
			width: 72upx;
			height: 72upx;
		}
	}
	.coupon-box{
		margin-top: 28upx;
		.coupon-item{
			margin-bottom: 14upx;
			position: relative;
			.coupon-left{
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: rgba(255, 255, 255, .5);
				width: 210rpx;
				height: 242rpx;
				background: #FF8A57;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				justify-content: center;
				.coupon-money{
					font-family:cursive;
					font-weight: 500;
					font-size: 118rpx;
					color: #FFFFFF;
				}
			}
			.coupon-right{
				height: 242rpx;
				background: linear-gradient( 90deg, #3D46C7 0%, #7781FD 100%);
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				justify-content: center;
				flex: 1;
				align-items: flex-start;
				padding-left: 40upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 26rpx;
				color: rgba(255, 255, 255, .5);
				position: relative;
				line-height: 44upx;
				.coupon-title{
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 34rpx;
					color: #FFFFFF;
					margin-bottom: 28upx;
				}
				.coupon-icon{
					width: 206upx;
					height: 113upx;
					position: absolute;
					right: 0;
					bottom: 0;
				}
			}
			.user-btn{
				width: 154rpx;
				height: 64rpx;
				line-height: 64rpx;
				border-radius: 48rpx;
				border: 1rpx solid #FFFFFF;
				text-align: center;
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				position: absolute;
				right: 24rpx;
				top: 24upx;
				.righttop-icon{
					width: 20upx;
					height: 20upx;
					margin-left: 6upx;
				}
			}
		}
	}
</style>
